package com.leetcode.string;

/**
 * @author Dennis Li
 * @date 2020/9/16 19:35
 */
public class LengthOfLastWord_58 {

    public int lengthOfLastWord(String s) {
        if (s.equals("")) return 0;
        int len = 0;
        boolean flag = s.charAt(s.length() - 1) == ' ';
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == ' ') {
                if (flag) continue;
                else return len;
            }
            len++;
            flag = false;
        }
        return len;
    }

}
